import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'

Vue.use(Router)

const routes = [
  {
    path: '/main',
    name: 'main',
    meta: {
      requireAuth: true,
    },
    component: resolve => require(['../components/Main.vue'], resolve),
    children: [
      {
        path: '/tahome',
        component: resolve => require(['../views/ta/Home.vue'], resolve)
      },
      {
        path: '/tawstb',
        component: resolve => require(['../views/ta/OnlineReporting.vue'], resolve)
      },
      {
        path: '/tachart',
        component: resolve => require(['../views/ta/DataAnalysis.vue'], resolve)
      },
      {
        path: '/taupload',
        component: resolve => require(['../views/ta/ReportUpload.vue'], resolve),
      },
      {
        path: '/tasubmit',
        component: resolve => require(['../views/ta/SubmitReport.vue'], resolve),
      },
      {
        path:'/tahistory',
        component: resolve => require(['../views/ta/ReportHistory.vue'], resolve),
      },{
        path:'/ta404',
        component: resolve => require(['../components/404.vue'],resolve),
      }
    ]
  }, {
    path: '/govmain',
    name: 'govmain',
    meta: {
      requireAuth: true,
    },
    component: resolve => require(['../components/Main.vue'], resolve),
    children: [
      {
        path: '/govhome',
        component: resolve => require(['../views/gov/Home.vue'], resolve)
      },
      {
        path: '/govnofill',
        component: resolve => require(['../views/gov/NoFill.vue'], resolve)
      },
      {
        path: '/govcomfill',
        component: resolve => require(['../views/gov/CompleteFill.vue'], resolve)
      },
      {
        path: '/govrefill',
        component: resolve => require(['../views/gov/ReFill.vue'], resolve)
      },
      {
        path: '/govcomre',
        component: resolve => require(['../views/gov/CompletedReview.vue'], resolve),
      },
      {
        path: '/govproview',
        component: resolve => require(['../views/gov/ProgressView.vue'], resolve),
      },
      {
        path: '/govvisit',
        component: resolve => require(['../views/gov/VisitAgency.vue'], resolve),
      },
      {
        path:'/govdata',
        component: resolve => require(['../views/gov/DataAnalysis.vue'], resolve)
      }
    ]
  },{
    path:'/govprint',
    name:'govprint',
    component:resolve => require(['../views/PrintReport.vue'],resolve)
  },{
    path: '*',
    beforeEnter: (to,from,next) => {
      if(store.state.istourism){
        this.a.push('ta404')
      }
    }
  }
]

const router = new Router({
  routes
})
//根据跳转路由的requireAuth参数进行判断，切换菜单及头部样式
router.beforeEach((to, from, next) => {
  if (to.matched.some(r => r.meta.requireAuth)) {
    let ista = true;
    if (to.path.indexOf('gov') > -1) {
      ista = false;
    }
    store.commit('IS_TOURISM', {flag: ista});//切换头部与左侧菜单
    store.dispatch('getSysInfo',ista).then(res =>{},error => {});
    
    next();
  } else {
    next();
  }
})

export default router
